home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / misc / mf-db.zip / CSAMPLE\UDK\MFUDK.C < prev    next >
Text File  |  1993-09-30  |  3KB  |  98 lines

  1. /*
  2.  
  3.    Sample UDK (user-defined key) dll
  4.  
  5.    (compiled under MSC 8.0 (VC++))
  6.  
  7.    You may do whatever you want with this.  It's free.
  8.  
  9. */
  10. #include <windows.h>
  11. #include <memory.h>
  12.  
  13.  
  14. /*
  15.       
  16.    MF.dll will call this function and pass the following parameters:
  17.    pass:
  18.       val 1   (LPSTR a)
  19.       val 2   (LPSTR b)
  20.       length  (Size of keys to compare)
  21.       type    (This will be a number >= 100)
  22.    
  23.    the 'type' is the 'type of index' specified when the index's where
  24.    created.  (i.e. When you called mfCreateDB you passed an array of
  25.    index types.  One of those 'types' was >= 100.  Whatever that
  26.    # was, it is now passed to you (as the type).  This allows you to
  27.    support multiple UDK's in one function.
  28.  
  29.    You should return:
  30.    returns:
  31.       0 == equal
  32.       1 == val 1 > val 2
  33.       -1 == val 1 < val 2
  34.  
  35.    Demonstrated in this example is a reverse-sorting for character fields
  36.    and a variable length char and INT field.  The 'type' passed for
  37.    these fields is:
  38.       1001 = reverse sorting characters
  39.       1002 = variable length char and INT
  40.  
  41.  
  42. */
  43. int FAR PASCAL _export mfUDK(LPSTR a, LPSTR b, int len, int type)
  44. {
  45.    int iReturnValue;
  46.  
  47.    switch(type){
  48.       case 1001:
  49.             // _fmemcmp is a MS-C runtime library routine.  (It is actually
  50.             // pretty quick, believe it or not...)
  51.             // Anycase, it returns the EXACT same parameters we need to
  52.             // return from this function...
  53.             // NOTE: To show the reverse-sorting, we just switched the
  54.             // order of the parameters to fmemcmp.  For 'alphabetical' 
  55.             // we would have put 'a' and then 'b'.
  56.          return(_fmemcmp((LPSTR)b, (LPSTR)a, len));
  57.          break;
  58.  
  59.       case 1002:
  60.             // NOTE: By using the value of  'len' we can make this 
  61.             // a 'variable' length string routine.  e.g. if the user
  62.             // made the key an 80 bytes, this routine would still
  63.             // work (by comparing the first 78 bytes and then the integer
  64.             // tacked onto the end...)
  65.  
  66.          iReturnValue = _fmemcmp((LPSTR)a, (LPSTR)b, len-2);
  67.             // We can stop checking now because the keys first set of 
  68.             // keys (the char[len]) doesn't match, therefore the value
  69.             // of the INT is irrelevant)
  70.          if (iReturnValue != 0)
  71.                return (iReturnValue);
  72.          if (*(int FAR *)(a+len-2) < *(int FAR *)(b+len-2))
  73.             return (-1);
  74.          if (*(int FAR *)(a+len-2) > *(int FAR *)(b+len-2))
  75.             return (1);
  76.  
  77.          return(0);  // exact match...
  78.          break;
  79.    }
  80.  
  81. }
  82.  
  83.  
  84. /*----------------------------------------------------------------------
  85.    This is required for 'windows' dll's.
  86.    Generally, you put any startup code that you might require,
  87.    initialize variables, allocate memory, etc...
  88. */
  89. int FAR PASCAL LibMain(
  90.         HANDLE  hModule,
  91.         WORD    wDataSeg,
  92.         WORD    cbHeapSize,
  93.         LPSTR   lpszCmdLine
  94.         )
  95. {
  96.    return 1;
  97. }
  98.